//
//  NSArray+Extend.m
//  XLDoctor
//
//  Created by longma on 2018/12/27.
//  Copyright © 2018年 XLH. All rights reserved.
//

#import "NSArray+MJUI.h"

@implementation NSArray (MJUI)

- (id)mj_filteredArrayUsingPredicate:(NSPredicate *)predicate {
    
    NSArray *filteredArray = [self filteredArrayUsingPredicate:predicate];
    if(filteredArray.count == 1){
        return filteredArray[0];
    }
    return nil;
}

- (id)mj_filteredArrayUsingPredicateFormat:(NSString *)predicateFormat {
    
    NSArray *filteredArray = [self filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:predicateFormat]];
    if(filteredArray.count == 1){
        return filteredArray[0];
    }
    return nil;
}

- (NSString *)mj_arrayConvertToString{
    
    NSError *parseError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:&parseError];
    
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

- ( BOOL )mj_isEqualToNumberArr:( NSArray *)arr2 {
    if (self. count   !=  arr2. count ) { // 两次数量不同，直接显示
        return NO ;
    } else { // 两个数量相同 , 比较字符串
        int hasSame = 0 ;
        for ( int i = 0 ; i < self. count ; i++) {
            NSNumber *picUrl1 = self[i];
            NSNumber *picUrl2 = arr2[i];
            if ([picUrl1 isEqualToNumber :picUrl2]) {
                hasSame++;
            }
        }
        if (hasSame < self. count ) { // 至少有一个不同
            return NO ;
        } else { // 两个元素相同， hasSame 不可能等于 arr1.count
            return YES ;
        }
    }
}

@end
